<?php
require_once("lib.Stratosphere.test.php");

if(!isset($myStratosphere))$myStratosphere=new Stratosphere(); 
$s_p=$myStratosphere->getPlatform(null);

$s_cmd=$_POST['cmd'];
$s_log=$_POST['log'];
$s_grp=$_POST['grp'];

if( $s_p=='ACE' ){
	$DEF_ENV_PLATASSRV='ACE' ;
	?>
	ServerLog
	<hr />
	<form method='POST'>
	<input type='-hidden' name='platform' value="<?php print( _get_safe_HTML_str($DEF_ENV_PLATASSRV) ); ?>" />
	command:  <select name='cmd' />
	<option value='---' selected >---</option>
	<option value='view' >show log</option>
	<option value='last' >show last (n) log</option>
	<option value='deleteL' >delete a log</option>
	<option value='deleteG' >delete a group</option>
	<option value='deleteA' >delete all</option>
	</select>
	log id:<input type='text' name='log' value="<?php print( _get_safe_HTML_str($s_log) ); ?>" />
	grp id:<input type='text' name='grp' value="<?php print( _get_safe_HTML_str($s_grp) ); ?>" />
	<input type='submit' value='Do it' />
	</form>
	<hr />
	Command:
	<br /><?php print(  _get_safe_HTML_str($s_cmd)  ); ?>
	<br />log id:<?php print( _get_safe_HTML_str($s_log) ); ?>
	<br />grp id:<?php print( _get_safe_HTML_str($s_grp) ); ?>
	<hr />
	Result:<br />
	<?php
	switch ($s_cmd) {
	case "view":
		//show log
		echo"<br /><pre>";
		print_r( $myServerLog->getLogFile( $s_grp,$s_log) );
		echo"</pre><br />Done.";
		break;
	case "last":
		//show last (n) log
		echo"<br /><pre>";
		print_r( $myServerLog->getLogFiles( $s_log ) );
		echo"</pre><br />Done.";
		break;
	case "deleteL":
		//delete a log
		$myServerLog->deleteLogFileByIndex( $s_grp,$s_log);
		echo "delete log [ grp:".$s_grp.",log:".$s_log."]" ;
		break;
	case "deleteG":
		//delete a group
		$myServerLog->deleteLogGroupByIndex( $s_grp );
		echo "delete group[".$s_grp."]";
		break;
	case "deleteA":
		//delete all
		$myServerLog->deleteAllLogByName( $setting['key'] );
		echo "delete all";
		break;
	default:
		echo "Unknow command";
	}
	$gid = $myServerLog->getMaxLogGroupIndex();
	$lid = $myServerLog->getMaxLogIndex($gid);
	?>
	<hr />
	Current:
	<br />Current Group ID :<?php print(  $gid  ); ?>
	<br />Current Log ID   :<?php print(  $lid  ); ?>
	<hr />
	Last 5:
	<br /><pre>
	<?php
		print_r(  $myServerLog->getLogFiles( 5 ) );
	?>
	</pre>
	<?php
}else{
	echo "This page work on [Stratosphere.ServerLog.ACE] Only";
}
?>
